//
// Created by 董一龙 on 2022/10/13.
//

#include "fqueue/segment_queue/mmap_queue/mmap_queue.h"

namespace fqueue {

    mmap_queue::mmap_queue(std::string const& filename, size_t mmap_size) {
        m_pBuffer = std::make_unique<memory_map_buffer>(filename, mmap_size);
        queue_operator_t::format(m_pBuffer->data(), m_pBuffer->size());
        assert(m_pBuffer != nullptr);
    }

    size_t mmap_queue::capacity() const {
        return queue_operator_t::capacity(m_pBuffer->data(), m_pBuffer->size());
    }

    size_t mmap_queue::size() const {
        return queue_operator_t::capacity(m_pBuffer->data(), m_pBuffer->size());
    }

    int mmap_queue::enqueue(const void *input, size_t input_length) {
        char const* input_buffer = static_cast<char const*>(input);
        return queue_operator_t::enqueue(m_pBuffer->data(), m_pBuffer->size(), input, input_length);
    }

    int mmap_queue::dequeue(void *output, size_t output_length) {
        return queue_operator_t::dequeue(m_pBuffer->data(), m_pBuffer->size(), output, output_length);

    }
} // fqueue